package com.EpidemicPrevention.service;

import com.EpidemicPrevention.mapper.VolunteerinfoMapper;
import com.EpidemicPrevention.pojo.User;
import com.EpidemicPrevention.pojo.Volunteerinfo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VolunteerinfoServiceIpml implements VolunteerinfoService{
    @Autowired

    private VolunteerinfoMapper volunteerinfoMapper;
    @Override
    public JSON addVolunteerinfo(Volunteerinfo volunteerinfo) {
        JSONObject json = new JSONObject();
        int code =0;
        code = volunteerinfoMapper.addVolunteerinfo(volunteerinfo);
        if (code ==1){
            json.put("msg","添加成功");
            json.put("code",1);
        }else {
            json.put("msg","添加失败");
            json.put("code",0);
        }
        return json;
    }
    @Override
    public JSON updateVolunteerinfo(Volunteerinfo volunteerinfo) {
        JSONObject json = new JSONObject();
        try {
            int code=0;
            code=volunteerinfoMapper.updateVolunteerinfo(volunteerinfo);
            if (code==1){
                json.put("msg","修改成功");
                json.put("code",1);
            }else{
                json.put("msg","修改失败");
                json.put("code",0);
            }
        }catch (Exception e){
            e.printStackTrace();
            json.put("msg","数据接口异常,请稍后再试");
            json.put("code",-1);
        }
        return json;
    }

    @Override
    public JSON deleteVolunteerinfo(int v_id) {
        JSONObject json = new JSONObject();
        int code =0;
        code = volunteerinfoMapper.deleteVolunteerinfo(v_id);
        if (code ==1){
            json.put("msg","删除成功");
            json.put("code",1);
        }else {
            json.put("msg","删除失败");
            json.put("code",0);
        }
        return json;
    }

    @Override
    public  List<Volunteerinfo> queryVolunteerinfo (int page, int limit,  String Keyword) {
        return volunteerinfoMapper.queryVolunteerinfo(page, limit, null);
    }

//id查询
    @Override
    public List<Volunteerinfo> selectVolunteerinfo(int v_id) {
        return volunteerinfoMapper.selectVolunteerinfo(v_id);
    }


    //关键字查看
    @Override
    public List<Volunteerinfo> selectWhereVolunteerinfo() {
        return volunteerinfoMapper.selectWhereVolunteerinfo();
    }
}
